/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.apt.matrimony.db;

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author HANHXINH
 */
public class ConvertDateTime {

    public static Date stringConvertToDate(String date) {
        Date d = null;

        try {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            d = (Date) sdf.parse(date);
        } catch (ParseException ex) {
            Logger.getLogger(ConvertDateTime.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return d;
    }

    public static String dateConvertToString(Date d) {
        String date = null;

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

        date = sdf.format(d.getTime());

        return date;

    }

    public static String getRegisterDate() {
        Date d = new Date();
        Date date = new Date(d.getTime());
        String df = ConvertDateTime.dateConvertToString(date);
        return df;
    }

    public static String addDate(String payment, String dateRegister) {

        dateRegister = ConvertDateTime.getRegisterDate();
        Date d = ConvertDateTime.stringConvertToDate(dateRegister);
        Calendar c = Calendar.getInstance();
       
        c.setTime(d);
       
        if (payment.equalsIgnoreCase("180.00")) {
            c.roll(Calendar.MONTH, 2);
        } else if (payment.equalsIgnoreCase("300.00")) {
            c.roll(Calendar.MONTH, 6);
        }else if (payment.equalsIgnoreCase("500.00")) {
            c.roll(Calendar.YEAR, 1);
        }

        Date getDate = (Date) c.getTime();
        String getDatef = ConvertDateTime.dateConvertToString(getDate);
        return getDatef;
    }

    public static void main(String[] args) {
        System.out.println("- Ngay hom nay: " + getRegisterDate());
        System.out.println("- Sau 1 nam: " + addDate("golder", getRegisterDate()));
    }
}
